<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title> 检测canvas画布上是否有透明或半透明像素点</title>
</head>
<body>
<canvas id="canvas"></canvas>
<script>
    // 检测canvas画布上是否有透明或半透明像素点
    HTMLCanvasElement.prototype.isSomeAlphaPixel = function () {
        let context = this.getContext('2d')
        let imageData = context.getImageData(0, 0, this.width, this.height).data;
        let isAlphaBackground = false;
        for(let index = 3; index < imageData.length; index += 4){
            if(imageData[index] !== 255){
                isAlphaBackground = true;
                break
            }
        }
        return isAlphaBackground
    }

    //测试
    var canvas = document.querySelector('#canvas');
    // 输出true或false
    console.log('检测canvas画布上是否有透明或半透明像素点', canvas.isSomeAlphaPixel());
    // 登录状态下不会出现这行文字，点击页面右上角一键登录
</script>
</body>
</html>